package affcom;

import java.awt.*;

public class TPanel extends Panel
{

// Author : Tom Yarker, 22695 Dorchester Drive, Geneseo, IL 61254
//          Phone: (309) 944-5955, E-Mail: tyarker@netexpress.net
// Purpose: Panel with 3D border. Border style is defined by an integer
//          array of any length. First value is width of a flat at the
//          edge of the panel. Second value is width of a band, which
//          initially rises towards the center. Third value is width of
//          another flat band at the top of the rise. Fourth value is
//          width of a band, which initially falls towards the center.
//          Fifth and subsequent values simply repeat this pattern of
//          flat, rising, flat, falling. For example;
//			A raised panel with insets - {4, 2, 4}
//          A raised rib around panel  - {4, 2, 1, 2, 4}
//          A thick rib and a thin rib - {4, 2, 2, 2, 2, 1, 0, 1, 4}
//          A raised panel with a rib  - {4, 4, 0, 0, 4, 1, 1, 1, 4}
// History: 08-18-97 Started

// Border style
	private boolean bump;
	private int[]   bord;
// Insets
	private Insets  iset;
// Default border
//	private int[]   defb = {1, 2, 1, 2, 6};
        private int[]   defb = {1, 1};

//-----------------------------------------------------

// Constructor, default layout and style
	public TPanel() {
		super(new BorderLayout());
		bump = true;
		setGaps(defb);

	}

//-----------------------------------------------------

// Constructor, default layout
// 1st argument is border style array
	public TPanel(int[] ib) {
		super(new BorderLayout());
		bump = true;
		setGaps(ib);
	}

//-----------------------------------------------------

// Constructor, default border style
// 1st argument is layout manager
	public TPanel(LayoutManager lm) {
		super(lm);
		bump = true;
		setGaps(defb);
	}

//-----------------------------------------------------

// Constructor
// 1st argument is layout manager
// 2nd argument is border style array
	public TPanel(LayoutManager lm, int[] ib) {
		super(lm);
		bump = true;
		setGaps(ib);
	}

//-----------------------------------------------------
// From this point on, routines are in alphabetic order
//-----------------------------------------------------

// Returns true if the 2nd border style
//   value currently represents a raise
    public boolean getBump() {
		return bump;
	}

//-----------------------------------------------------

// Returns the current border style
    public int[] getGaps() {
		return bord;
	}

//-----------------------------------------------------

// Ensures space for border
	public Insets getInsets() {
		return iset;
	}

//-----------------------------------------------------

// Draws surrounding 3D effect.
	public void paint(Graphics gr)
        {
                super.paint(gr);
		int i1;
		int iv = 0;
		int xy = 0;
		boolean up = bump;
		Dimension sz = getSize();
		int wd = sz.width    - 1;
		int ht = sz.height   - 1;
		int nv = bord.length - 1;
		gr.setColor(getBackground());
		while (iv < nv) {
			i1 = bord[iv];
			iv = iv +  1 ;
			xy = xy + i1 ;
			i1 = i1 + i1 ;
			wd = wd - i1 ;
			ht = ht - i1 ;
			i1 = bord[iv];
			iv = iv +  1 ;
			for (int i = 0; i < i1; i = i + 1) {
				gr.draw3DRect(xy, xy, wd, ht, up);
				xy = xy + 1;
				wd = wd - 2;
				ht = ht - 2;
			}
			up = !up;
		}
//		super.paint(gr);
	}

//-----------------------------------------------------

// Sets the state of the 2nd border style value
// 1st argument is true for a rise, false for a fall
	public void setBump(boolean up) {
		if (up == bump) return;
		bump = up;
		if (isShowing()) repaint();
	}

//-----------------------------------------------------

// Sets the border style
// 1st argument is border style array
	public void setGaps(int[] ib) {
		int tv = 0;
		int nv = ib.length;
		bord = new int[nv];
		for (int i = 0; i < nv; i = i + 1) {
			int wd = Math.abs(ib[i]);
			bord[i] = wd;
			tv = tv + wd;
		}
		iset = new Insets(tv, tv, tv, tv);
		if (isShowing()) repaint();
	}



//-----------------------------------------------------

}